# -*- coding: utf-8 -*-

from THS.THSTrader import THSTrader
import time

if __name__ == "__main__":
    trader = THSTrader(r'D:\同花顺软件\同花顺\xiadan.exe')    # 连接客户端

    # 获取当前可用资金
    balance_info = trader.get_balance()
    print(balance_info)
    exit()

    # 获取当前持有的股票
    position_info = trader.get_position()
    if len(position_info) > 0:
        print(position_info)
    else:
        print('没有持仓')

    # 买入股票
    order_info = trader.buy(stock_no="601628", amount=100, price=0.218)
    print(order_info)
    order_num = order_info['entrust_info']
    print('订单编号：', order_num)

    # 卖出股票
    order_info = trader.sell(stock_no="601628", amount=100, price=5)
    print(order_info)

    # 如果买入下单成功，尝试撤单
    time.sleep(2)
    if order_info["success"] == True:
        print("撤单测试--->", end="")
        cancel_info = trader.cancel_entrust(entrust_no=order_info["entrust_no"])
        print(cancel_info)

    # 查询今日所有委托单
    entrust_info = trader.get_today_entrusts()
    if entrust_info.empty:
        print('今日没有委托单')
    else:
        print(entrust_info)

    # 查询今日所有订单
    trade_info = trader.get_today_trades()
    if trade_info.empty:
        print('今日没有订单')
    else:
        print(trade_info)

